using System;
using System.Globalization;
using System.Web;
using iPhOwa.Exchange;
using iPhOwa.Exchange.ContentClasses;
using iPhOwa.Exchange.Managers;

namespace iPhOwa.Web
{
	public partial class ViewNote : iPhOwaPage
	{
		/// <summary>
		/// Page load event.
		/// </summary>
		protected void Page_Load(object sender, EventArgs e)
		{
			Message message = MessageManager.Get(Path, OwaSession);

			if(message == null)
			{
				throw new ApplicationException("Unable to get note.");
			}

			if(message.ParentName != null)
			{
				Folder parentFolder = FolderManager.Get(message.ParentName, OwaSession);

				if(parentFolder != null)
				{
					parentNameLabel.Text = parentFolder.DisplayName;
					backPanel.Visible = true;

					backPanel.Href = string.Format(CultureInfo.InvariantCulture, "ViewFolder.aspx?path={0}", parentFolder.Href);
				}
			}

			if(!message.Read)
			{
				MessageManager.MarkAsRead(Path, OwaSession);
			}

			Title = string.Format(CultureInfo.CurrentUICulture, "{0} - iPhOwa", message.Subject);

			createdLabel.Text = DateUtility.MakeFriendlyShortDate(message.DateReceived);
			subjectLabel.Text = message.Subject;
			bodyLabel.Text = HttpUtility.HtmlDecode(message.HtmlDescription);
		}
	}
}